package com.satan.fmmall.controller;

import com.satan.fmmall.service.UserService;
import com.satan.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName LoginController
 * @Description TODO
 * @date 2022/3/28 18:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
@Api(value = "提供用户的登录和注册接口",tags = "用户管理")
public class UserController {
    @Resource
    private UserService userService;


    @ApiOperation("用户登录接口")
    @GetMapping("/login")
    public ResultVo login(@RequestParam("username") String username,
                                @RequestParam(value = "password") String password){
        ResultVo resultVo = userService.checkLogin(username, password);
        return resultVo;
    }

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public ResultVo register(String username,String password){
        ResultVo resultVO = userService.userResgit(username, password);
        return resultVO;
    }
    @ApiOperation("用户信息接口")
    @GetMapping("/getInfo")
    public ResultVo getUserInfo(@RequestHeader("Authorization") String token){
        ResultVo resultVO = userService.getUserInfoByToken(token);
        return resultVO;
    }

    @ApiOperation("用户退出登录接口")
    @GetMapping("/logout")
    public ResultVo logout(@RequestHeader("Authorization") String token){
        System.out.println("token:"+token);
        return userService.logout(token);

    }
}
